package com.qf.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsAdminMapper;
import com.qf.mapper.DtsBrandMapper;
import com.qf.mapper.DtsCategoryMapper;
import com.qf.pojo.DtsBrand;
import com.qf.vo.CatVo;
import org.omg.PortableInterceptor.SUCCESSFUL;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Date;
import java.util.List;

@Service
public class BrandServiceImpl implements BrandService {

    @Autowired
    private DtsBrandMapper brandMapper;
    @Autowired
    private DtsCategoryMapper categoryMapper;


    @Override
    public IPage<DtsBrand> queryBrandPage(Integer id, String name, Integer page, Integer limit, String sort, String order) {

        IPage<DtsBrand> ipage = new Page<>();
        QueryWrapper<DtsBrand> queryWrapper = new QueryWrapper<>();
        if (!StringUtils.isEmpty(id)){
            queryWrapper.eq("id",id);
        }
        if (!StringUtils.isEmpty(name)){
            queryWrapper.eq("name",name);
        }
        if (!StringUtils.isEmpty(sort)&&!StringUtils.isEmpty(order)){
            if (order.equalsIgnoreCase("asc")){
                queryWrapper.orderByAsc(sort);
            }else {
                queryWrapper.orderByDesc(sort);
            }
        }
        IPage<DtsBrand> resultPage = brandMapper.selectPage(ipage, queryWrapper);


        return resultPage;
    }

    @Override
    public DtsBrand add(DtsBrand brand) {
        brand.setAddTime(new Date());
        brand.setUpdateTime(new Date());

        brandMapper.insert(brand);

        return brand;
    }

    @Override
    public void update(DtsBrand brand) {

        brand.setUpdateTime(new Date());
        brandMapper.updateById(brand);
    }

    @Override
    public void delete(Integer id) {
        brandMapper.deleteById(id);

    }



}
